package com.ilibrary.web.action;

import java.util.ArrayList;
import java.util.List;

import com.ilibrary.base.MyBaseAction;
import com.ilibrary.constants.MyConstants;
import com.ilibrary.service.BookService;
import com.ilibrary.service.BorrowService;
import com.ilibrary.service.CategoryService;
import com.ilibrary.service.CollectService;
import com.ilibrary.service.UserInfoService;
import com.ilibrary.utils.MyColumnIndicator;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.BookVO;
import com.ilibrary.web.vo.BorrowVO;
import com.ilibrary.web.vo.CollectVO;
import com.ilibrary.web.vo.UserInfoVO;

public class UserCenterAction extends MyBaseAction {
	private UserInfoService userInfoService;
	private CategoryService categoryService;
	private BorrowService borrowService;
	private BookService bookService;
	private CollectService collectService;
	
	public UserInfoService getUserInfoService() {
		return userInfoService;
	}
	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	public CategoryService getCategoryService() {
		return categoryService;
	}
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
	public BookService getBookService() {
		return bookService;
	}
	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}
	public BorrowService getBorrowService() {
		return borrowService;
	}
	public void setBorrowService(BorrowService borrowService) {
		this.borrowService = borrowService;
	}
	public CollectService getCollectService() {
		return collectService;
	}
	public void setCollectService(CollectService collectService) {
		this.collectService = collectService;
	}
	
	@Override
	public String execute() throws Exception {
		UserInfoVO loginUser = (UserInfoVO)getSSN().getAttribute(MyConstants.ILIBRARY_lOGIN_USER);
		if(loginUser == null) {
			return "login";
		}
		ResultDto<BorrowVO> resultDtoNewB = borrowService.findByUserIdAndStatus(loginUser.getUserId(), MyColumnIndicator.BORROW_STATUS_NEW);
		ResultDto<BorrowVO> resultDtoCompB = borrowService.findByUserIdAndStatus(loginUser.getUserId(), MyColumnIndicator.BORROW_STATUS_COMPLETE);
		ResultDto<CollectVO> resultDtoColl = collectService.findByUserId(loginUser.getUserId());
		List<BorrowVO> borrowVONewList = resultDtoNewB.getResultList();
		List<BorrowVO> borrowVOCompList = resultDtoCompB.getResultList();
		List<CollectVO> collectVOList = resultDtoColl.getResultList();
		getRQ().setAttribute("borrowVONewList", borrowVONewList);
		getRQ().setAttribute("borrowVOCompList", borrowVOCompList);
		getRQ().setAttribute("collectVOList", collectVOList);
		return SUCCESS;
	}
	
}
